package com.ivncorp.evnproject;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ivncorp.evnproject.helpers.LocationTracker;
import com.ivncorp.evnproject.helpers.MyMarker;
import com.ivncorp.evnproject.model.UploadTable;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

public class ActivityViewItemMap extends Activity {

	LocationTracker locationTracker;

	private UploadTable object;
	private MyMarker marker;
	private ImageView ivgps;
	private ImageView ivgeneral;
	private ImageView ivdetail;
	private TextView txtCode;
	private TextView txtName;

	//private TextView txtTime;
	DisplayImageOptions options;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_item_map);

		options = new DisplayImageOptions.Builder()
		.showImageForEmptyUri(R.drawable.ic_action_camera)
		.showImageOnFail(R.drawable.ic_action_group)
		.resetViewBeforeLoading(true)
		.cacheOnDisk(true)
		.imageScaleType(ImageScaleType.EXACTLY)
		.bitmapConfig(Bitmap.Config.RGB_565)
		.considerExifParams(true)
		.displayer(new FadeInBitmapDisplayer(300))
		.build();
		
		ivgps = (ImageView) findViewById(R.id.ivMapGps);
		ivgeneral = (ImageView) findViewById(R.id.ivMapGeneral);
		ivdetail = (ImageView) findViewById(R.id.ivMapDetail);
		txtCode = (TextView) findViewById(R.id.txtViewItemMapCode);
		txtName = (TextView) findViewById(R.id.txtGalleryViewItemMapName);
	
	//	txtTime = (TextView) findViewById(R.id.txtGalleryViewItemMapTime);

		locationTracker = new LocationTracker(this);
		Intent intent = getIntent();
		if (intent.getStringExtra("input").equals("object")) {
			object = (UploadTable) intent.getSerializableExtra("object");
		} else if (intent.getStringExtra("input").equals("marker")) {

			marker = (MyMarker) intent.getSerializableExtra("mymarker");
		}
		if (object != null) {

			txtCode.setText(object.getCode());
			txtName.setText(object.getName());
			//txtTime.setText(object.getTimestamp());
		

			String uriGPS = object.getImage1();
			if (uriGPS != null) {
				
				imageLoader.displayImage(uriGPS, ivgps, options); 
			}
			String uriGeneral = object.getImage2();
			if (uriGeneral != null) {
				imageLoader.displayImage(uriGeneral, ivgeneral, options);
			}
			String uriDetail = object.getImage3();
			if (uriDetail != null) {
				
				imageLoader.displayImage(uriDetail, ivdetail, options);
			}
		}
		if (marker != null) {
			txtName.setText(marker.getmLabel());
		}
		getActionBar().setDisplayShowHomeEnabled(true);
		getActionBar().setDisplayHomeAsUpEnabled(true);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	public void imageclick(View view) {

		Intent intent = new Intent(this, ActivityFullScreenImage.class);

		switch (view.getId()) {
		case R.id.layoutViewMapGps:
			intent.putExtra("url", object.getImage1());
			break;
		case R.id.layoutViewMapGeneral:
			intent.putExtra("url", object.getImage2());
			break;
		case R.id.layoutViewMapDetail:
			intent.putExtra("url", object.getImage3());
			break;
		default:
			break;
		}

		startActivity(intent);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if(item.getItemId()==android.R.id.home)
		{
			finish();
		}
		return super.onOptionsItemSelected(item);
	}

//	
	

}
